//
//  GKZYMyInfoHeaderCell.m
//  GKZY_CLASS
//
//  Created by chenziqiang on 15/12/7.
//  Copyright © 2015年 eenet. All rights reserved.
//

#import "GKZYMyInfoHeaderCell.h"
#import "GKZYMyInfoModel.h"
#import "xxptmobile.h"

@interface GKZYMyInfoHeaderCell()
@property (nonatomic, strong) UIImageView *headImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subLabel;
@property (nonatomic,strong) UILabel *topLine;
@property (nonatomic,strong) UILabel *bottomLine;
@end

@implementation GKZYMyInfoHeaderCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.headImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.subLabel];
        [self addSubview:self.topLine];
        [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self);
            make.height.equalTo(@(0.5));
        }];
        [self addSubview:self.bottomLine];
        [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(self);
            make.height.equalTo(@(0.5));
        }];
    }
    return self;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
}

#pragma mark - Setter For Property

- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = ({
            UIImageView *head = [[UIImageView alloc] init];
            head.backgroundColor = [UIColor redColor];
            CGFloat imgUnit = 45;
            head.layer.cornerRadius = imgUnit/2;
            head.layer.masksToBounds = YES;
            head.layer.borderColor = [UIColor lightGrayColor].CGColor;
            head.layer.borderWidth = 1;
            head.contentMode = UIViewContentModeScaleAspectFit;
            head;
        });
    }
    return _headImageView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel *topLine = [UILabel new];
            topLine.font = [UIFont systemFontOfSize:16];
            topLine;
        });
    }
    return _titleLabel;
}

- (UILabel *)subLabel{
    if (!_subLabel) {
        _subLabel = ({
            UILabel *topLine = [UILabel new];
            topLine.textColor = [UIColor colorWithRed:153/255.f green:153/255.f blue:153/255.f alpha:1];
            topLine.font = [UIFont systemFontOfSize:16];
            topLine;
        });
    }
    return _subLabel;
}

-(UILabel *)topLine{
    if (!_topLine) {
        _topLine = ({
            UILabel *topLine = [UILabel new];
            topLine.backgroundColor = [UIColor lightGrayColor];
            topLine;
        });
    }
    return _topLine;
}

-(UILabel *)bottomLine{
    if (!_bottomLine) {
        _bottomLine = ({
            UILabel *bottomLine = [UILabel new];
            bottomLine.backgroundColor = [UIColor lightGrayColor];
            bottomLine;
        });
    }
    return _bottomLine;
}

-(void)setData:(GKZYMyInfoModel *)data{
    _data = data;
    
    
    if(data.img){
        self.headImageView.image = data.img;
    }else if (data.imgName) {
        self.headImageView.image = [ResourceHelper archiveImage:data.imgName withType:data.imgSuffix];
    }
    
    if (data.showArrows) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else{
        self.accessoryType = UITableViewCellAccessoryNone;
    }
    
    if (self.data.isDetail) {
        [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.right.equalTo(self.contentView.mas_right).offset(-12);
            make.size.mas_equalTo(CGSizeMake(45, 45));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(12);
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.height.mas_equalTo(@20);
            make.width.lessThanOrEqualTo(@20).priorityMedium();
        }];
        self.subLabel.hidden = YES;
        
    }else{
        [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.left.equalTo(self.contentView.mas_left).offset(12);
            make.size.mas_equalTo(CGSizeMake(45, 45));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImageView.mas_right).offset(8);
            make.centerY.equalTo(self.contentView.mas_centerY).offset(-10);
            make.height.mas_equalTo(@20);
            make.width.lessThanOrEqualTo(@20).priorityMedium();
        }];
        
        self.subLabel.hidden = NO;
        [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.centerY.equalTo(self.contentView.mas_centerY).offset(10);
            make.height.equalTo(self.titleLabel);
            make.width.lessThanOrEqualTo(@20).priorityMedium();
        }];
    }
    
    
    self.titleLabel.text = data.title;
    self.subLabel.text = data.subTitle;
}

@end
